﻿Public Class ViewSalary

    Private Sub ViewSalary_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        UI.FormatDataGrid(DataGridView1)
        UI.SetPlaceHolder(txtsearch)
        loaddata()
        loadsalary()
    End Sub
    Private Sub loaddata()
        DataGridView1.DataSource = cmdp.ExecuteDataTable("SELECT e.EmpId,e.EmpName,s.BaseSalary FROM Employee e INNER JOIN Salary s on s.EmpId=e.EmpId")
    End Sub
    Private Sub loadsalary()
        For i = 0 To DataGridView1.Rows.Count - 1
            If DataGridView1.Rows(i).Cells("EmpId").Value > 0 Then
                'MessageBox.Show(DataGridView3.Rows(i).Cells(1).Value)
                cmdp.Parameters("@EmpId") = DataGridView1.Rows(i).Cells("EmpId").Value
                DataGridView1.Rows(i).Cells("kidonage").Value = cmdp.ExecuteScalar("SELECT COUNT(*) FROM [Child] WHERE EmpId=@EmpId AND Active=true")
                DataGridView1.Rows(i).Cells("kid").Value = (DataGridView1.Rows(i).Cells("kidonage").Value * 5)
                DataGridView1.Rows(i).Cells("Total").Value = (DataGridView1.Rows(i).Cells("kidonage").Value * 5) + DataGridView1.Rows(i).Cells("BaseSalary").Value
            End If
        Next
    End Sub

    Private Sub DataGridView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
        loadsalary()
    End Sub
End Class